﻿using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;

namespace PropertyExpression.ControllableQuery.Demo
{
    internal class Program
    {
        private static void Main()
        {
            var random = new Random();
            NonQuery.New(new {}, "DELETE FROM Purchase ").Execute();
            NonQuery.New(new {}, "DELETE FROM Customer ").Execute();
            var purchaseId = 0;
            var stopwatch = new Stopwatch();
            stopwatch.Start();
            for (var customerId = 0; customerId < 100000; customerId++)
            {
                NonQuery.New(new {
                    CustomerId = customerId, Name = Guid.NewGuid().ToString()
                }, "@p.Insert(\"Customer\")").Execute();
                for (var j = 0; j < random.Next(30); j++)
                    NonQuery.New(new {
                        PurchaseId = purchaseId++, CustomerId = customerId, Summ = (decimal) random.Next(1000000000)/1000
                    }, "@p.Insert(\"Purchase\")").Execute();
            }
            stopwatch.Stop();
            Console.WriteLine(stopwatch.ElapsedMilliseconds);
        }

        static Program()
        {
            RegisterRazorConfiguration();
        }

        private static void RegisterRazorConfiguration([CallerFilePath] string filePath = "")
        {
            RazorConfiguration.Register(filePath, new[] {
                typeof(DB).Namespace
            }, MethodBase.GetCurrentMethod());
        }
    }
}
